package com.gk.javaservice.util.javaRequest;

import com.alibaba.fastjson.JSONObject;
import com.gk.javaservice.util.rest.HttpURLConnectionUtils;
import com.gk.javaservice.util.rest.RestUtil;
import net.sf.json.JSONArray;

import java.util.HashMap;

public class JavaRequest {

   public static JSONArray hasDirectory(String ip,String path){
       try {
       RestUtil restUtil = new RestUtil();

      // String resultString = restUtil.load("http://"+ip+":9092/File/hasDirectory","path="+path);

           HashMap params = new HashMap();
           params.put("path",path);
      String resultString= HttpURLConnectionUtils.postForm("http://"+ip+":9092/File/hasDirectory",null,params);
           // System.out.println(resultString);
       JSONObject jsonObject = JSONObject.parseObject(resultString);

       String data=jsonObject.getString("data");
       JSONArray json = JSONArray.fromObject(data );
       return json;
       } catch (Exception e) {

           // TODO: handle exception

           // System.out.print(e.getMessage());
           return null;
       }
   }
    public static JSONArray hasDirectoryGet(String ip,String path){
        try {
            RestUtil restUtil = new RestUtil();
            String resultString = restUtil.gatLoad(
                    "http://"+ip+":9092/File/hasDirectory",
                    "path="+path);
            //  // System.out.println(resultString);
            JSONObject jsonObject = JSONObject.parseObject(resultString);

            String data=jsonObject.getString("data");
            JSONArray json = JSONArray.fromObject(data );
            return json;
        } catch (Exception e) {

            // TODO: handle exception

            // System.out.print(e.getMessage());
            return null;
        }
    }

}
